package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {
    //花色
    private  static final String[] SUITS ={"♥","♠","♦","♦"};

    public static List<Card> buyCard(){
        List<Card> cards = new ArrayList<>();

        for (int i = 0; i < SUITS.length; i ++){
            for (int j = 1; j <= 13 ; j++){
                Card card = new Card(SUITS[i],j);
                cards.add(card);
            }
        }
        return cards;
    }

    //洗牌
    public static void shuffle( List<Card> cards){
        Random random = new Random();//生成随机数

        for (int i = cards.size()-1; i > 0; i--){
            int j = random.nextInt(i);
            //交换
            Card tmp = cards.get(i);
            cards.set(i,cards.get(j));//更新i下标的值
            cards.set(j,tmp);///更新j下标的值
        }

    }


    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println(cards);
        System.out.println("洗牌：");
        shuffle(cards);
        System.out.println(cards);

        //3个人，每个人轮流接牌5张
        //每个人轮流接的牌都放到哪里
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>>  hand = new ArrayList<>();//二维数组
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5; i++){
            for (int j = 0; j < 3; j++){
                //接牌的动作
                Card card = cards.remove(0);
                //如何放到指定的人手里
                hand.get(j).add(card);//j下标获取list
            }
        }
        System.out.println("第一个人的牌：");
        System.out.println(hand1);
        System.out.println("第二个人的牌：");
        System.out.println(hand2);
        System.out.println("第三个人的牌：");
        System.out.println(hand3);
        System.out.println("剩下的牌：");
        System.out.println(cards);
    }
}
